<?php
// 系统默认控制器
class UserAction extends CommonAction {
	public function index(){
		$id=session('id');
		$account = M('User'); // 实例化模型类
		$count=$account->count();
		//分页显示文章列表，每页8篇文章
		import('ORG.Util.Page');
		$page=new Page($count,20);//后台管理页面默认一页显示8条文章记录
		$page->setConfig('prev', "上一页");//上一页
		$page->setConfig('next', '下一页');//下一页
		$page->setConfig('first', '首页');//第一页
		$page->setConfig('last', '尾页');//最后一页
		$page->setConfig('theme',' %first% %upPage%  %linkPage%  %downPage% %end%');
		//设置分页回调方法
		$show=$page->show();
		$firstpage=$page->firstRow;
		$lastpage=$page->listRows;
		$list=$account->query("select *, (select zhiwei from ys_level where ys_user.level = ys_level.id ORDER BY id desc limit 0,1) as `zhiwei` from ys_user where  ys_user.section='$id' limit $firstpage,$lastpage");
		$this->assign('accounts_list', $list); // 数据列表变量赋值
		$this->assign('page_method',$show);//分页列表变量赋值
		$this->display(); // 输出模板
	}
	public function addyewu(){
		$account = M('User'); // 实例化模型类
		$list=$account->query("select id,rname from ys_user where level=7");
		$this->assign('accounts_list', $list); // 数据列表变量赋值
		//dump ($account);
	    $this->display();
	}
	public function ywaddsave(){
		$user=D('User');
		$data=$user->create();
		if(false!==$user->add()){
			$this->success('注册成功');
			//$this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("注册成功",function(){window.parent.frmright.location.reload();top.Dialog.close()})})</script>','utf-8');
		}else{
			header("Content-Type:text/html; charset=utf-8");
            $this->success('注册成功');
			//$this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("用户名重复或注册失败！",function(){window.parent.frmright.location.reload();top.Dialog.close()})})</script>','utf-8');
		}
	}
	public function useredit(){
		$id=$_GET['id'];
		$useredit=M('User');
		$data=$useredit->where("id=$id")->find();
		//dump($useredit);
		$this->assign('id',$id);
		$this->assign('rname',$data['rname']);
		$this->assign('username',$data['username']);
		$this->assign('password',$data['password']);
		$this->assign('mobile',$data['mobile']);
		$this->assign('qq',$data['qq']);
		$this->assign('birthday',$data['birthday']);
		$this->assign('section',$data['section']);
		$account = M('User'); // 实例化模型类
		$list=$account->query("select id,rname from ys_user where level=7");
		$this->assign('accounts_list', $list); // 数据列表变量赋值
		$this->display();
	}
	public function xgsave(){
		$password=$_POST['password'];//密码赋值
		//echo ($password);
		if(!empty($password)){
		header("Content-Type:text/html; charset=utf-8");
		$custom=M('User');
		$data = array('password'=>md5($_POST[$password]),'mobile'=>$_POST['mobile'],'rname'=>$_POST['rname'],'qq'=>$_POST['qq'],'birthday'=>$_POST['birthday'],'section'=>$_POST['section']);
		$id=$_GET['id'];
		$custom->where('id='.$id)->setField($data); // 根据条件保存修改的数据
		$this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("密码已修改,成功提交!",function(){window.parent.frmright.location.href="/index.php/Custom";top.Dialog.close()})})</script>','utf-8');
			}else{
		header("Content-Type:text/html; charset=utf-8");
		$custom=M('User');
		$data = array('mobile'=>$_POST['mobile'],'rname'=>$_POST['rname'],'qq'=>$_POST['qq'],'birthday'=>$_POST['birthday'],'section'=>$_POST['section']);
		$id=$_GET['id'];
		$custom->where('id='.$id)->setField($data); // 根据条件保存修改的数据
		$this->show('<script type="text/javascript" src="__PUBLIC__/libs/js/jquery.js"></script><script type="text/javascript">$(function(){top.Dialog.alert("成功提交",function(){window.parent.frmright.location.href="/index.php/Custom";top.Dialog.close()})})</script>','utf-8');
			}
	}
    }
?>